import { defHttp } from '/@/utils/http/axios';
import {
  GetTrademarkListResultModel,
  saveTrademarkResultModel,
  updateTrademarkResultModel,
  removeTrademarkResultModel,
  TrademarkItem,
  trademarkListModel,
} from './model/trademarkModel';

enum Api {
  GetTrademarkList = '/admin/product/baseTrademark',
  GetAllTrademarkList = '/admin/product/baseTrademark/getTrademarkList',
  SaveTrademark = '/admin/product/baseTrademark/save',
  UpdateTrademark = '/admin/product/baseTrademark/update',
  RemoveTrademark = '/admin/product/baseTrademark/remove',
}

/**
 * @description: 获取trademark分页列表
 */
export function getTrademarkListApi(page: number, limit: number) {
  return defHttp.get<GetTrademarkListResultModel>({
    url: Api.GetTrademarkList,
    // 字符串形式会拼在地址栏，params参数
    // 对象形式就是查询字符串参数
    params: `/${page}/${limit}`,
  });
}

/**
 * @description: 获取所有trademark列表
 */
export function getAllTrademarkListApi() {
  return defHttp.get<trademarkListModel>({
    url: Api.GetAllTrademarkList,
  });
}

/**
 * @description: 添加trademark
 */
export function saveTrademarkApi(tmName: string, logoUrl: string) {
  return defHttp.post<saveTrademarkResultModel>({
    url: Api.SaveTrademark,
    data: {
      tmName,
      logoUrl,
    },
  });
}

/**
 * @description: 修改trademark
 */
export function updateTrademarkApi(trademark: TrademarkItem) {
  return defHttp.put<updateTrademarkResultModel>({
    url: Api.UpdateTrademark,
    data: trademark,
  });
}

/**
 * @description: 删除trademark
 */
export function removeTrademarkApi(id: number) {
  return defHttp.delete<removeTrademarkResultModel>({
    url: Api.RemoveTrademark,
    params: `/${id}`,
  });
}
